name: Release

permissions:
  contents: write

on:
  
  push:
    branches: 
    - main
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest

    steps:
      - name: Git checkout
        uses: actions/checkout@v3
        
      - name: Get short sha commit
        id: git
        run: |
          echo "short_sha=$(git rev-parse --short $GITHUB_SHA)" >> "$GITHUB_OUTPUT"
      
      - name: Get latest version
        id: version
        uses: martinbeentjes/npm-get-version-action@main

      - name: Git
        run: |
          echo Branch name is: ${{ github.ref_name }}
          echo Short sha: ${{ steps.git.outputs.short_sha }}
          echo Version is: ${{ steps.version.outputs.current-version }}

      - name: Release
        uses: softprops/action-gh-release@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: v${{ steps.version.outputs.current-version }}
          name: v${{ steps.version.outputs.current-version }}
          generate_release_notes: true
          draft: false
          prerelease: false
